import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import { join } from "path";
// import electron from "vitejs-plugin-electron";
import styleImport from "vite-plugin-style-import";

const root = join(__dirname, "src/render");
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      script: {
        refSugar: true,
      },
    }),
    // electron(),
    styleImport({
      libs: [
        {
          libraryName: "element-plus",
          esModule: true,
          ensureStyleFile: true,
          resolveStyle: (name) => {
            name = name.slice(3);
            return `element-plus/packages/theme-chalk/src/${name}.scss`;
          },
          resolveComponent: (name) => {
            return `element-plus/lib/${name}`;
          },
        },
      ],
    }),
  ],
  root,
  base: "./", // index.html 中静态资源加载位置
  server: {
    port: 3000,
  },
  resolve: {
    alias: {
      "@render": join(__dirname, "src/render"),
      "@main": join(__dirname, "src/main"),
      "@src": join(__dirname, "src"),
      "@root": __dirname,
    },
  },
  build: {
    outDir: join(__dirname, "dist/render"),
    emptyOutDir: true,
    // minify: false,
    // commonjsOptions: {},
    assetsDir: "", // 相对路径 加载问题
    sourcemap: false,
  },
  optimizeDeps: {
    exclude: ["electron-is-dev", "electron-store"],
  },
});
